using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Markup;
using Common;
using Common.Enum;
using Controls;
using SExperiment;
using SSettings;
using SWellPlate;

namespace MainView.MainControls
{
	public partial class UCPatientInfoForWell : UserControl, IComponentConnector
	{
		public delegate void DelegateOnAutoIndexEvent(object sender, EventArgs e);

		public IList<Well> SelectedWells;

		public static readonly DependencyProperty GridColumnsProperty = DependencyProperty.Register("GridColumns", typeof(GridColumns), typeof(UCPatientInfoForWell), new PropertyMetadata(null, OnGridColumnsChanged));

		public static readonly DependencyProperty IsDecryptProperty = DependencyProperty.Register("IsDecrypt", typeof(bool), typeof(UCPatientInfoForWell), new UIPropertyMetadata(true, OnBasicOptionChanged));

		public Sample sample = new Sample(0);

		private bool isLoad;

		private bool bUpdate = true;

		public GridColumns GridColumns
		{
			get
			{
				return (GridColumns)GetValue(GridColumnsProperty);
			}
			set
			{
				SetValue(GridColumnsProperty, value);
			}
		}

		public bool IsDecrypt
		{
			get
			{
				return (bool)GetValue(IsDecryptProperty);
			}
			set
			{
				SetValue(IsDecryptProperty, value);
			}
		}

		public event DelegateOnAutoIndexEvent OnAutoIndex;

		private static void OnGridColumnsChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCPatientInfoForWell uCPatientInfoForWell = sender as UCPatientInfoForWell;
			if (uCPatientInfoForWell != null)
			{
				uCPatientInfoForWell.ResetColumns();
			}
		}

		private static void OnBasicOptionChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCPatientInfoForWell uCPatientInfoForWell = sender as UCPatientInfoForWell;
			if (uCPatientInfoForWell != null)
			{
				uCPatientInfoForWell.patientInfoGrid.IsEnabled = uCPatientInfoForWell.IsDecrypt;
			}
		}

		public UCPatientInfoForWell()
		{
			InitializeComponent();
			patientInfoGrid.DataContext = sample;
			base.Loaded += Root_Loaded;
			AddHandler(UCPlate.OnSelectionChangedRoutedEvent, new RoutedEventHandler(WellPlateSelectionChanged_RoutedEvent), true);
		}

		private void Root_Loaded(object sender, RoutedEventArgs e)
		{
			if (!isLoad)
			{
				isLoad = true;
				uCWellPlate.RefreshHeight();
			}
		}

		private void ResetColumns()
		{
			string message = Utility.GetMessage("Colon");
			foreach (ColumnInfo column in GridColumns.Columns)
			{
				if ((column.Info & 4) != 4)
				{
					continue;
				}
				switch (column.FieldName)
				{
				case "WellCell.Well.Sample.PatientInfo.ID":
					sample_index_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_index_tb.Text = column.Header + message;
					sample_index.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Name":
					patientName_tb.Text = column.Header + message;
					patientName_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					patientName.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Sex":
					comboSex_tb.Text = column.Header + message;
					comboSex_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSex.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSex.ItemsSource = column.DataSource;
					break;
				case "WellCell.Well.Sample.PatientInfo.Age":
					sample_age_tb.Text = column.Header + message;
					sample_age_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_age.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Specimen":
					comboSample_specimen_tb.Text = column.Header + message;
					comboSample_specimen_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_specimen.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_specimen.ItemsSource = column.DataSource;
					break;
				case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
					specimenDatePicker_tb.Text = column.Header + message;
					specimenDatePicker_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					specimenDatePicker.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Doctor":
					comboSample_doctor_tb.Text = column.Header + message;
					comboSample_doctor_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_doctor.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_doctor.ItemsSource = column.DataSource;
					break;
				case "WellCell.Well.Sample.PatientInfo.Office":
					comboSample_office_tb.Text = column.Header + message;
					comboSample_office_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_office.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					comboSample_office.ItemsSource = column.DataSource;
					break;
				case "WellCell.Well.Sample.PatientInfo.CaseID":
					sample_case_id_tb.Text = column.Header + message;
					sample_case_id_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_case_id.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.BedID":
					sample_bed_id_tb.Text = column.Header + message;
					sample_bed_id_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_bed_id.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.InPatientID":
					sample_inpatient_id_tb.Text = column.Header + message;
					sample_inpatient_id_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_inpatient_id.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.OutPatientID":
					sample_outpatient_id_tb.Text = column.Header + message;
					sample_outpatient_id_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_outpatient_id.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Diagnosis":
					sample_diagnosis_tb.Text = column.Header + message;
					sample_diagnosis_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_diagnosis.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfo.Remark":
					sample_remark_tb.Text = column.Header + message;
					sample_remark_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_remark.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.SampleName":
					sample_name_tb.Text = column.Header + message;
					sample_name_tb.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					sample_name.Visibility = ((!column.Visibility) ? Visibility.Collapsed : Visibility.Visible);
					break;
				case "WellCell.Well.Sample.PatientInfoCustomData.":
				case null:
				{
					if (column.FieldIndex < 0)
					{
						return;
					}
					string name = "coustom_" + column.FieldIndex;
					string name2 = "tb_coustom_" + column.FieldIndex;
					while (sample.PatientInfo.CustomData.Count <= column.FieldIndex)
					{
						sample.PatientInfo.CustomData.Add("");
					}
					string message2 = Utility.GetMessage("Colon");
					CreateControlOrChangeType(name, column);
					if (tb_Panel.FindName(name2) == null)
					{
						TextBlock textBlock = new TextBlock();
						textBlock.Height = 24.0;
						textBlock.VerticalAlignment = VerticalAlignment.Center;
						textBlock.HorizontalAlignment = HorizontalAlignment.Left;
						textBlock.Margin = new Thickness(5.0, 5.2, 5.0, 5.2);
						textBlock.Text = column.Header + message2;
						textBlock.Name = name2;
						tb_Panel.Children.Add(textBlock);
						RegisterName(name2, textBlock);
					}
					else
					{
						SetItemsVisible(tb_Panel.FindName(name2), column.Visibility, column.Header + message2);
						SetItemsVisible(control_Panel.FindName(name), column.Visibility);
					}
					break;
				}
				}
			}
		}

		private void coustom_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			FrameworkElement frameworkElement = sender as FrameworkElement;
			if (frameworkElement == null)
			{
				return;
			}
			int result = -1;
			string[] array = frameworkElement.Name.Split('_');
			if (array.Length == 2)
			{
				int.TryParse(array[1], out result);
			}
			if (result < 0)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				if (sample.PatientInfo.CustomData.Count <= result)
				{
					continue;
				}
				if (sender is DatePicker)
				{
					DatePicker datePicker = sender as DatePicker;
					if (datePicker.SelectedDate.HasValue && !string.IsNullOrEmpty(sample.PatientInfo.CustomData[result]))
					{
						item.CustomData[result] = datePicker.SelectedDate.Value.ToString("yyyy/MM/dd");
					}
				}
				else
				{
					item.CustomData[result] = sample.PatientInfo.CustomData[result];
				}
			}
		}

		private void InsterControl(Control control, string name, int index)
		{
			control.Margin = new Thickness(5.0, 5.0, 5.0, 5.0);
			control.Height = 24.0;
			control.Name = name;
			control.HorizontalAlignment = HorizontalAlignment.Stretch;
			control.VerticalAlignment = VerticalAlignment.Center;
			if (index > -1)
			{
				control_Panel.Children.RemoveAt(index);
				UnregisterName(name);
				control_Panel.Children.Insert(index, control);
				RegisterName(name, control);
			}
			else
			{
				control_Panel.Children.Add(control);
				RegisterName(name, control);
			}
		}

		private void CreateControlOrChangeType(string name, ColumnInfo info)
		{
			Binding binding = new Binding();
			binding.Path = new PropertyPath("CustomData[" + info.FieldIndex + "]");
			binding.Source = sample.PatientInfo;
			binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
			binding.NotifyOnSourceUpdated = true;
			binding.Mode = BindingMode.TwoWay;
			object obj = control_Panel.FindName(name);
			switch (info.Type)
			{
			case EColumnType.TextBox:
				if (obj == null)
				{
					TextBoxEx textBoxEx = new TextBoxEx();
					textBoxEx.SetBinding(TextBox.TextProperty, binding);
					textBoxEx.TextChanged += coustom_TextChanged;
					InsterControl(textBoxEx, name, -1);
				}
				else if (!(obj is TextBox))
				{
					int index2 = control_Panel.Children.IndexOf(obj as FrameworkElement);
					TextBoxEx textBoxEx2 = new TextBoxEx();
					textBoxEx2.SetBinding(TextBox.TextProperty, binding);
					textBoxEx2.TextChanged += coustom_TextChanged;
					InsterControl(textBoxEx2, name, index2);
				}
				break;
			case EColumnType.ComboBox:
				if (obj == null)
				{
					ComboBox comboBox = new ComboBox();
					comboBox.Style = (Style)FindResource("ComboBoxDefault");
					comboBox.ItemsSource = info.DataSource;
					comboBox.SetBinding(ComboBox.TextProperty, binding);
					comboBox.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(coustom_TextChanged));
					comboBox.IsEditable = true;
					InsterControl(comboBox, name, -1);
				}
				else if (!(obj is ComboBox))
				{
					int index3 = control_Panel.Children.IndexOf(obj as FrameworkElement);
					ComboBox comboBox2 = new ComboBox();
					comboBox2.Style = (Style)FindResource("ComboBoxDefault");
					comboBox2.ItemsSource = info.DataSource;
					comboBox2.SetBinding(ComboBox.TextProperty, binding);
					comboBox2.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(coustom_TextChanged));
					comboBox2.IsEditable = true;
					InsterControl(comboBox2, name, index3);
				}
				break;
			case EColumnType.DateTime:
				if (obj == null)
				{
					DatePicker datePicker = new DatePicker();
					datePicker.SetBinding(DatePicker.SelectedDateProperty, binding);
					datePicker.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(coustom_TextChanged));
					InsterControl(datePicker, name, -1);
				}
				else if (!(obj is DatePicker))
				{
					int index = control_Panel.Children.IndexOf(obj as FrameworkElement);
					DatePicker datePicker2 = new DatePicker();
					datePicker2.SetBinding(DatePicker.SelectedDateProperty, binding);
					datePicker2.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(coustom_TextChanged));
					InsterControl(datePicker2, name, index);
				}
				break;
			}
		}

		private void SetItemsVisible(object obj, bool visible, string header = "")
		{
			if (obj is TextBlock)
			{
				TextBlock textBlock = obj as TextBlock;
				textBlock.Text = header;
				textBlock.Visibility = ((!visible) ? Visibility.Collapsed : Visibility.Visible);
			}
			else if (obj is FrameworkElement)
			{
				FrameworkElement frameworkElement = obj as FrameworkElement;
				frameworkElement.Visibility = ((!visible) ? Visibility.Collapsed : Visibility.Visible);
			}
		}

		public void setContextMenuDisable()
		{
			uCWellPlate.SetContextMenu_Disable();
		}

		public void SetWellData(Experiment experiment)
		{
			uCWellPlate.Experiment = experiment;
			uCWellPlate.SetContextMenu_UCPatientInfoForWell();
			SelectedWells = (from s in uCWellPlate.SelectedWells
				where s.Well.Sample != null
				select s.Well).ToList();
			uCWellPlate.SetBinding(UCPlate.IsDecryptProperty, new Binding("IsDecrypt")
			{
				Source = this
			});
			MenuItem menuItem = new MenuItem();
			menuItem = new MenuItem();
			menuItem.Header = Utility.GetMessage("sample_index");
			menuItem.Click += Auto_index_Click;
			uCWellPlate.GetContextMenu().Items.Insert(1, menuItem);
		}

		private void Auto_index_Click(object sender, RoutedEventArgs e)
		{
			if (this.OnAutoIndex != null)
			{
				this.OnAutoIndex(sender, new EventArgs());
			}
		}

		public void RefreshInfo()
		{
			WellPlateSelectionChanged_RoutedEvent(null, null);
		}

		private void WellPlateSelectionChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			bUpdate = false;
			SelectedWells = (from s in uCWellPlate.SelectedWells
				where s.Well.Sample != null && (s.Well.Sample.Items[0].SampleType == SampleType.RetestSample || s.Well.Sample.Items[0].SampleType == SampleType.Unknown)
				select s.Well).ToList();
			if (SelectedWells.Count > 1)
			{
				if (!patientInfoGrid.IsEnabled && IsDecrypt)
				{
					patientInfoGrid.IsEnabled = true;
				}
				GetSamePatientInfo(sample.PatientInfo);
			}
			else if (SelectedWells.Count == 1)
			{
				if (!patientInfoGrid.IsEnabled && IsDecrypt)
				{
					patientInfoGrid.IsEnabled = true;
				}
				SelectedWells[0].Sample.PatientInfo.CopyTo(sample.PatientInfo);
				sample.SampleName = SelectedWells[0].Sample.SampleName;
			}
			else
			{
				sample.SampleName = string.Empty;
				sample.PatientInfo.Clear();
				patientInfoGrid.IsEnabled = false;
			}
			bUpdate = true;
		}

		private void GetSamePatientInfo(PatientInfo samePatientInfo)
		{
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			IList<string> list2 = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.SampleName).Distinct().ToList();
			if (list2.Count == 1)
			{
				sample.SampleName = list2[0];
			}
			else
			{
				sample.SampleName = null;
			}
			while (sample.PatientInfo.CustomData.Count < list[0].CustomData.Count)
			{
				sample.PatientInfo.CustomData.Add("");
			}
			IList<string> list3 = list.Select((PatientInfo s) => s.ID).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.ID = list3[0];
			}
			else
			{
				samePatientInfo.ID = null;
			}
			list3 = list.Select((PatientInfo s) => s.Name).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Name = list3[0];
			}
			else
			{
				samePatientInfo.Name = null;
			}
			list3 = list.Select((PatientInfo s) => s.Sex).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Sex = list3[0];
			}
			else
			{
				samePatientInfo.Sex = null;
			}
			list3 = list.Select((PatientInfo s) => s.Age).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Age = list3[0];
			}
			else
			{
				samePatientInfo.Age = null;
			}
			list3 = list.Select((PatientInfo s) => s.Specimen).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Specimen = list3[0];
			}
			else
			{
				samePatientInfo.Specimen = null;
			}
			list3 = list.Select((PatientInfo s) => s.SpecimenDate).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.SpecimenDate = list3[0];
			}
			else
			{
				samePatientInfo.SpecimenDate = null;
			}
			list3 = list.Select((PatientInfo s) => s.Doctor).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Doctor = list3[0];
			}
			else
			{
				samePatientInfo.Doctor = null;
			}
			list3 = list.Select((PatientInfo s) => s.Office).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Office = list3[0];
			}
			else
			{
				samePatientInfo.Office = null;
			}
			list3 = list.Select((PatientInfo s) => s.CaseID).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.CaseID = list3[0];
			}
			else
			{
				samePatientInfo.CaseID = null;
			}
			list3 = list.Select((PatientInfo s) => s.BedID).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.BedID = list3[0];
			}
			else
			{
				samePatientInfo.BedID = null;
			}
			list3 = list.Select((PatientInfo s) => s.InPatientID).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.InPatientID = list3[0];
			}
			else
			{
				samePatientInfo.InPatientID = null;
			}
			list3 = list.Select((PatientInfo s) => s.OutPatientID).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.OutPatientID = list3[0];
			}
			else
			{
				samePatientInfo.OutPatientID = null;
			}
			list3 = list.Select((PatientInfo s) => s.Diagnosis).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Diagnosis = list3[0];
			}
			else
			{
				samePatientInfo.Diagnosis = null;
			}
			list3 = list.Select((PatientInfo s) => s.Remark).Distinct().ToList();
			if (list3.Count == 1)
			{
				samePatientInfo.Remark = list3[0];
			}
			else
			{
				samePatientInfo.Remark = null;
			}
			IList<int> list4 = list.Select((PatientInfo s) => s.CustomData.Count).Distinct().ToList();
			if (list4.Count != 1)
			{
				return;
			}
			int i;
			for (i = 0; i < list4[0]; i++)
			{
				list3 = list.Select((PatientInfo s) => s.CustomData[i]).Distinct().ToList();
				if (list3.Count == 1)
				{
					samePatientInfo.CustomData[i] = list3[0];
				}
				else
				{
					samePatientInfo.CustomData[i] = string.Empty;
				}
			}
		}

		private void sample_name_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<Sample> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample).ToList();
			foreach (Sample item in list)
			{
				item.SampleName = sample.SampleName;
			}
			uCWellPlate.RefreshCellText();
		}

		private void sample_index_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.ID = sample.PatientInfo.ID;
			}
			uCWellPlate.RefreshCellText();
		}

		private void patientName_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Name = sample.PatientInfo.Name;
			}
			uCWellPlate.RefreshCellText();
		}

		private void sample_age_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Age = sample.PatientInfo.Age;
			}
		}

		private void sample_case_id_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.CaseID = sample.PatientInfo.CaseID;
			}
		}

		private void sample_bed_id_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.BedID = sample.PatientInfo.BedID;
			}
		}

		private void sample_inpatient_id_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.InPatientID = sample.PatientInfo.InPatientID;
			}
		}

		private void sample_outpatient_id_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.OutPatientID = sample.PatientInfo.OutPatientID;
			}
		}

		private void sample_diagnosis_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Diagnosis = sample.PatientInfo.Diagnosis;
			}
		}

		private void sample_remark_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Remark = sample.PatientInfo.Remark;
			}
		}

		private void comboSex_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Sex = sample.PatientInfo.Sex;
			}
		}

		private void comboSample_specimen_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Specimen = sample.PatientInfo.Specimen;
			}
		}

		private void specimenDatePicker_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			DatePicker datePicker = (DatePicker)sender;
			foreach (PatientInfo item in list)
			{
				if (datePicker.SelectedDate.HasValue && !string.IsNullOrEmpty(sample.PatientInfo.SpecimenDate))
				{
					item.SpecimenDate = datePicker.SelectedDate.Value.ToString("yyyy/MM/dd");
				}
			}
		}

		private void comboSample_doctor_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Doctor = sample.PatientInfo.Doctor;
			}
		}

		private void comboSample_office_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (!bUpdate)
			{
				return;
			}
			IList<PatientInfo> list = (from s in SelectedWells
				where s.Sample != null
				select s.Sample.PatientInfo).ToList();
			foreach (PatientInfo item in list)
			{
				item.Office = sample.PatientInfo.Office;
			}
		}
	}
}
